package MTT::Libs::Param::Params;

use Data::Dumper;

use Moose;
use MTT::Libs::Param::Param;

has params => ( is => 'rw', isa => 'HashRef', default => sub { {} } );

sub add_param {
	my ($self, $param) = @_;

	return unless ref $param;
	
	$self->params->{ $param->name } = $param;
}

sub get_params {
	my ($self) = @_;

	my @params;
	push @params, $self->params->{$_} foreach keys %{ $self->params };
	return \@params;
}

sub load_all_params {
	my ($self, $schema) = @_;
	
	my $params = {};
	foreach my $p ( $schema->resultset('Param')->all() ) {
		my $param = MTT::Libs::Param::Param->new({
				id => $p->id,
				name => $p->name,
				descr => $p->descr,
				compute => $p->compute || '' 
			});

		$params->{ $param->name } = $param;
	}

	$self->params( $params );
	return $self;
}

__PACKAGE__->meta->make_immutable;
1;

